package cn.com.contec.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import cn.com.contec.bean.EcgFileInfoMethods;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

public class ReviewThread extends Thread{
	private FileInputStream stream;
	private Handler handler;
	private boolean run = true;
	public boolean isRun() {
		return run;
	}
	public void setRun(boolean run) {
		this.run = run;
	}
	int c;
	public ReviewThread(String  id,Handler handler,Activity activity)
	{
		
		EcgFileInfoMethods ecgFileInfoMethods = new EcgFileInfoMethods(activity);
		File reviewfile = ecgFileInfoMethods.getEcgFile(id);
		this.handler = handler;
		 try {
			stream = new FileInputStream(reviewfile.getPath());
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Override
	public void run() {
		try {	
			sleep(500);
			while ((c = stream.read()) != -1&&run) {
				if (c != 0) {
					Message message = new Message();
					message.what = 1;
					Bundle data = new Bundle();
					data.putInt("ave", c);
					message.setData(data);
					handler.sendMessage(message);
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
